package com.fjec.user.controller;

import com.fjec.common.protocol.JsonResult;
import com.fjec.user.service.IDevopsLoginService;
import com.fjec.user.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/")
public class LoginController {

    @Autowired
    private ILoginService loginServ;

    @Resource
    private IDevopsLoginService devopsLoginService;

    /**
     *
     * @param jsCode
     * @param coopId
     * @return
     * @throws Exception
     */
    @PostMapping("/login/wxapp/reg")
    public JsonResult wxSmallAppReg(@RequestParam String jsCode,
                                    @RequestParam(required = false) Long coopId) throws Exception {
        return loginServ.wxSmallAppReg(jsCode, coopId);
    }

    /**
     * 微信小程序登录
     *
     * @param jsCode   微信登录码
     * @param nickName 昵称
     * @param headPic  头像
     * @return
     * @throws Exception
     */
    @PostMapping("/login/wxapp")
    public JsonResult wxSmallAppLogin(@RequestParam String jsCode,
                                      @RequestParam(required = false) Long coopId,
                                      @RequestParam(required = false) String nickName,
                                      @RequestParam(required = false) String headPic) throws Exception {
        return loginServ.wxSmallAppLogin(jsCode, coopId, nickName, headPic);
    }

    /**
     * 运维登录
     *
     * @param userName
     * @param userPwd
     * @return
     * @throws Exception
     */
    @PostMapping("/login/devops")
    public JsonResult devopsLogin(@RequestParam String userName,
                                  @RequestParam String userPwd) throws Exception {
        return devopsLoginService.login(userName, userPwd);
    }
}
